﻿@{
    Layout = "_LayoutH";
    @model DeviceInfo
}
<div id="app" v-cloak>
    <form class="form-horizontal" onsubmit="return false">
        <div class="box-body">
            <div class="form-group">
                <label class="col-sm-2 control-label">站点名称</label>
                <div class="col-sm-10">
                    @await Component.InvokeAsync("ClientInfo")
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">监控点名称</label>
                <div class="col-sm-10">
                    <input class="form-control" v-model="DeviceName" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">模块类型</label>
                <div class="col-sm-10">
                    <input class="form-control" v-model="DeviceType" type="text" disabled>
                </div>
            </div>
            @*<div class="form-group">
                <label class="col-sm-2 control-label">电表ip地址</label>
                <div class="col-sm-10">
                    <input class="form-control" v-model="DeviceIp" type="text" disabled>
                </div>
            </div>*@
            <div class="form-group">
                <label class="col-sm-2 control-label">模块出厂编号</label>
                <div class="col-sm-10">
                    <input class="form-control" v-model="DeviceSerialNum" type="text" disabled>
                </div>
            </div>
            @*<div class="form-group">
                    <label class="col-sm-2 control-label">备注</label>
                    <div class="col-sm-10">
                        <textarea v-model="Description" class="form-control" rows="3" placeholder="备注...100个字符以内"></textarea>
                        <p class="textarea-numberbar"><em class="textarea-length">{{count}}</em>/100</p>
                    </div>
                </div>*@
        </div>
        <div class="box-footer">
            <div class="pull-right box-tools">
                <input v-on:click="addL" class="btn btn-primary radius" type="submit" v-model="submit">
            </div>
        </div>
    </form>
</div>

@section scripts{
    <script>
        var app = new Vue({
            el: "#app",
            data: {
                submit: "添加",
                DeviceId:"@Model.DeviceId",
                ClientId: "@Model.ClientId",
                DeviceName: "@Model.DeviceName",
                DeviceType: "@Model.DeviceType",
                @*DeviceIp: "@Model.DeviceIp",*@
                DeviceSerialNum: "@Model.DeviceSerialNum",
                Description: "@Model.Description"
            },
            computed: {
                count: function () {
                    return this.strLength(this.Description, false);//描述信息字段长度计算
                }
            },
            mounted: function(){
                var _self = this;
                _self.$nextTick(function () {
                    if (_self.DeviceId > 0) {

                        _self.submit = "修改";
                    }
                    //_self.$refs.Remark.clientWidth = _self.$refs.DeptName.clientWidth;
                });
            },
            methods: {
                addL: function () {
                    var _self = this;
                    if (_self.DeviceName.length <= 0) {
                        layer.msg("模块名称不能为空", { icon: 2 });
                        return false;
                    }
                    if (_self.ClientId.length <= 0) {
                        layer.msg("所在区域信息不能为空", { icon: 2 });
                        return false;
                    }
                    var index = layer.load(1, {
                        shade: [0.1, '#fff'] //0.1透明度的白色背景
                    });
                    var data = {
                        DeviceId: _self.DeviceId,
                        ClientId: _self.ClientId,
                        DeviceName: _self.DeviceName,
                        DeviceType: _self.DeviceType,
                        //DeviceIp: _self.DeviceIp,
                        DeviceSerialNum: _self.DeviceSerialNum,
                        Description: _self.Description,
                    };
                    yui.$axiospostform('/DeviceInfo/AddOrUpdate1', data)
                        .then(function (response) {
                            if (response.data.Item1 === 101) {
                                layer.tips(response.data.Item2, '..layui-layer-setwin', {
                                    tips: [1, '#3595CC'],
                                    time: 3000
                                });
                                layer.close(index);
                                parent.app.searchL();
                                return false;
                            }
                            if (response.data.Item1) {
                                layer.msg(response.data.Item2, { icon: 1, time: 1000 });
                                setTimeout(function () {
                                    yui.layer_close3();
      
                                }, 500);
                            } else {
                                layer.msg(response.data.Item2 || errorMsg, { icon: 5 });
                            }
                            layer.close(index);
                            parent.app.searchL();
                        })
                        .catch(function (error) {
                            layer.close(index);
                        });
                }
            }
        });
    </script>
}